package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.BookDinnerSearchModel;
import com.jiayang.hhotel.ui.BookDinnerSearchDetailsActivity;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/23 0023.
 * 订餐查询适配器
 */

public class BookDinnerSearchAdapter extends SwipeMenuAdapter<BookDinnerSearchAdapter.ViewHolder> {

    private List<BookDinnerSearchModel> mList;
    private Context t;

    public BookDinnerSearchAdapter(Context context, List<BookDinnerSearchModel> list){
        this.mList=list;
        this.t=context;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.book_dinner_search_item,null);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        BookDinnerSearchModel model=mList.get(position);
        holder.orderNum.setText(model.getId());
        holder.canBiao.setText(model.getStandardMeal());
        holder.canTingHao.setText(model.getRestaurantNumber());
        holder.personCount.setText(model.getPersonCount());
        holder.canBie.setText(model.getState());
        holder.form.setText(model.getForm());
        holder.date.setText(model.getDate());
        holder.details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent start=new Intent(t, BookDinnerSearchDetailsActivity.class);
                t.startActivity(start);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        TextView orderNum;//订单号
        TextView canBiao;//餐标
        TextView canTingHao;//餐厅号
        TextView personCount;//人数
        TextView canBie;//餐别
        TextView form;//形式
        TextView date;//日期

        Button details;//查看详情

        public ViewHolder(View itemView) {
            super(itemView);
            orderNum= (TextView) itemView.findViewById(R.id.tv_order_num);
            canBiao= (TextView) itemView.findViewById(R.id.tv_canBiao);
            canTingHao= (TextView) itemView.findViewById(R.id.tv_canTingHao);
            personCount= (TextView) itemView.findViewById(R.id.tv_person_count);
            canBie= (TextView) itemView.findViewById(R.id.tv_canBie);
            form= (TextView) itemView.findViewById(R.id.tv_form);
            date= (TextView) itemView.findViewById(R.id.tv_date);
            details= (Button) itemView.findViewById(R.id.bt_details);
        }
    }
}
